// models/Order.js
module.exports = (sequelize, DataTypes) => {
  return sequelize.define('Order', {
    id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, comment: '订单 ID' },
    buyerId: { type: DataTypes.INTEGER, allowNull: false, comment: '买家 ID' },
    sellerId: { type: DataTypes.INTEGER, allowNull: false, comment: '卖家 ID' },
    itemId: { type: DataTypes.INTEGER, allowNull: false, comment: '商品 ID' },
    status: {
      type: DataTypes.ENUM('pending', 'completed', 'cancelled'),
      defaultValue: 'pending',
      comment: '订单状态',
    },
  }, {
    tableName: 'orders',
    timestamps: true, // 自动维护 createdAt、updatedAt 字段
    paranoid: true,   // 启用 deletedAt 软删除
    deletedAt: 'deletedAt', // 软删除字段重命名
    underscored: true, // 开启下划线命名风格
    charset: 'utf8mb4', // 指定字符集
    collate: 'utf8mb4_general_ci', // 使用 utf8mb4 字符集的排序规则
    comment: '订单表',
  });
};
